﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="B2B.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>AdminManagePostBuyRequest</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
     <script type="text/javascript">        
         function Xoa(maspmua)
         {
            var trang = <%= ViewData["page"]%>
            var json = {
                id:trang,
                XoaMaSanPhamMua: maspmua
            };
            $.ajax({
                url: '/Admin/AdminManagePostBuyRequest',
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(json),
                success: function (response) {
                    alert(response);
                }
            });
        }

    </script>
    <h4>Management Post Buy Request</h4>
    <table cellpadding="5" cellspacing="5" style="width: 100%" border="1">
        <tr>
            <th>Name product</th>                  
            <th>Catalog</th>                                                                                                                                                  
            <th>Estimated Order Quantity</th>                                                                                      
            <th>Status</th>       
            <th>Date</th>
        </tr> 
        <% for (int i = 0; i < ((ArrayList)ViewData["ds_SanPhamMua"]).Count; i++)
           {
               PostBuyRequest ds = ((PostBuyRequest)((ArrayList)ViewData["ds_SanPhamMua"])[i]);%>
        <tr>
            <td><%=((PostBuyRequest)ds).TenSanPham%></td>
            <td><%=((PostBuyRequest)ds).TenDanhMuc%></td>
            <td><%=((PostBuyRequest)ds).SoLuongCanMua%></td>
            <td><% if(((PostBuyRequest)ds).TinhTrang == 0)
                    { %>
                        <h6>Waiting Accept</h6> 
                <% } %>
                <% else if(((PostBuyRequest)ds).TinhTrang == 1)
                    { %>
                        <h6>Accepted</h6>
                <% } %>
                <% else if(((PostBuyRequest)ds).TinhTrang == 2)
                    { %>
                        <h6>Refuse</h6>
                <% } %>
                                                    
            </td>
            <td><%=((PostBuyRequest)ds).NgayDang%></td>
            <td>
                <a onclick="Xoa('<%=((PostBuyRequest)ds).MaSanPhamMua%>')">Delete </a>|
                <a href="AdminUpdatePostBuyRequest?id=<%=((PostBuyRequest)ds).MaSanPhamMua%>&TinhTrang=<%=((PostBuyRequest)ds).TinhTrang%>">Update</a>
            </td>
        </tr>
        <% } %>
        <tr><td colspan="6"><% 
                    int totalRow = (int)ViewData["tongDong"];
                    int totalPage = 0;
                    int itemInPage = 10;
                    if (totalRow % itemInPage == 0)
                    {
                        totalPage = totalRow / itemInPage;
                    }
                    else
                    {
                        totalPage = (totalRow / itemInPage) + 1; 
                    }
                    for (int i = 1; i <= totalPage; i++)
                    { 
                        int cur_page = (int)ViewData["page"];
                        if(i == cur_page)
                        { %> 
                            <a href="/Admin/AdminManagePostBuyRequest?XoaMaSanPhamMua=0&id=<%= i %>">[<%= i %>]</a>
                     <% } 
                        else 
                        { %>
                            <a href="/Admin/AdminManagePostBuyRequest?XoaMaSanPhamMua=0&id=<%= i %>"><%= i %></a>
                     <% }
                    } %></td></tr>
    </table>
</asp:Content>
